package com.easy.controller;

import com.easy.bean.Cart;
import com.easy.bean.Order;
import com.easy.bean.Orderaddress;
import com.easy.bean.User;
import com.easy.service.ICartService;
import com.easy.service.IOrderaddressService;
import com.easy.util.LayData;
import com.easy.util.Page;
import com.easy.util.Result;
import com.easy.util.SYS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("orderaddress")
public class OrderaddressController {
    @Autowired
    IOrderaddressService orderaddressService;


    @RequestMapping("list")
    @ResponseBody
    public LayData getList(Page page, String text,HttpSession session,int orderid) {
        System.out.println("进入cartlist方法");
        User user = (User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        List<Orderaddress> list = orderaddressService.getList(page, text, user.getId(),orderid);
        int count = orderaddressService.getCount(text, user.getId());
        System.out.println(count);
        return new LayData(count,list);
    }
    @RequestMapping("delete")
    @ResponseBody
    public int delete(int orderaddressid, int userid,int orderid){
        return orderaddressService.delete(orderaddressid,userid,orderid);
    }

    @RequestMapping("add")
    @ResponseBody
    public LayData add(HttpSession session, Orderaddress orderaddress){
        System.out.println("进入add方法");

        User user=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);

        System.out.println("当前userid="+user.getId());
        orderaddress.setUserid(user.getId());
        return LayData.success(orderaddressService.add(orderaddress));
    }

    @RequestMapping("edit")
    @ResponseBody
    public int edit(Orderaddress orderaddress){
        return orderaddressService.edit(orderaddress);
    }

    @RequestMapping("getorderaddressbyid")
    @ResponseBody
    public Orderaddress getOrderAddressByID(int orderid){
        return orderaddressService.getOrderaddressByID(orderid);
    }


    /*@PostMapping("/updateQuantity")
    @ResponseBody
    public Result updateQuantity(@RequestParam("productid") int productId,
                                 @RequestParam("userid") int userId,
                                 @RequestParam("count") int count) {
        Cart cart = new Cart();
        cart.setProductid(productId);
        cart.setUserid(userId);
        cart.setCount(count);

        int result = cartService.edit(cart);
        return Result.success(result);
    }*/

}
